{	Problem: http://codeforces.ru/problemset/problem/14/B
	Verdict: Accepted
}
{$R+,S+,Q+,I+,C+,M+,H+,O-}
uses SysUtils;
var i,n,x,r,j,c:longint; a,b:array[1..110] of longint;  f:boolean;
procedure swap(var a,b:longint);
var t:longint;
begin
t:=a;
a:=b;
b:=t;
end;
procedure qsort(l,r:longint);
var i,j,x:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
  while a[i]<x do inc(i);
  while a[j]>x do dec(j);
  if i<=j then begin
    swap(a[i],a[j]);
    swap(b[i],b[j]);
    inc(i);
    dec(j);
  end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
begin
read(n,x);
for i:=1 to n do begin
  read(a[i],b[i]);
  if a[i]>b[i] then swap(a[i],b[i]);
end;
qsort(1,n);
f:=true;
for i:=1 to n do
  for j:=1 to n do begin
    if b[i]<a[j] then begin
      f:=false;
      break;
    end;
  end;
if f then begin
  r:=0;
  for i:=1 to n do
    if ((a[i]<x) and (b[i]<x)) or (a[i]>x) then begin
        if b[i]<x then c:=x-b[i] else
        if a[i]>x then c:=a[i]-x;
        if c>r then r:=c;
    end;
  write(r);
end else write(-1);
end.